package com.waqwb.servlet;

import com.waqwb.dao.DAOFactory;
import com.waqwb.dao.UserDAO;
import com.waqwb.entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author JokerQ
 * @date 2020/7/15 - 15:11
 */
@WebServlet(name = "RegisterServlet")
public class RegisterServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        String email= request.getParameter("email");
        String nickname=request.getParameter("nickname");
        String password=request.getParameter("password");
        UserDAO userDAO= DAOFactory.getUserDAO();
        User user=new User();
        user.setEmail(email);
        user.setNickname(nickname);
        user.setPassword(password);
        userDAO.saveUser(user);
        response.sendRedirect("login.jsp");
    }
}
